/*************************************************************************
  > File Name: 1006.cpp
  > Author: skt
  > Mail: sktsxy@gmail.com
  > Created Time: 2015年09月13日 星期日 11时27分20秒
 ************************************************************************/

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <complex>
#include <cassert>
// #pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
#define LL long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define MAXN 40005
template <typename T> inline void checkMax(T &a, T b) {a = a>b?a:b;}
template <typename T> inline void checkMin(T &a, T b) {a = a<b?a:b;}
typedef pair<int, int> PII;
typedef vector<int> vi;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int INF = 0x3fffffff;
int T, N;

char str[MAXN], str1[MAXN];

int sa[MAXN], r[MAXN], Rank[MAXN], height[MAXN], Wa[MAXN], Wb[MAXN], Wv[MAXN], Ws[MAXN];

int cmp(int *r, int a, int b, int l) {
	return r[a] == r[b] && r[a + l] == r[b + l];
}
void calheight(int *r, int *sa, int n) {
	int i, j, k = 0;
	for (i = 0; i < n; height[Rank[i ++]] = k)
		for (k ? k -- : 0, j = sa[Rank[i] - 1]; r[i + k] == r[j + k]; k ++);
}
void da(int *r, int *sa, int n, int m) {
	int i, j, p, *x = Wa, *y = Wb, *t;
	for (i = 0; i < m; i ++) Ws[i] = 0;
	for (i = 0; i < n; i ++) Ws[x[i] = r[i]] ++;
	for (i = 1; i < m; i ++) Ws[i] += Ws[i - 1];
	for (i = n - 1; i >= 0; i --) sa[-- Ws[x[i]]] = i;
	for (j = 1, p = 1; p < n; j *= 2, m = p) {
		for (p = 0, i = n - j; i < n; i ++) y[p ++] = i;
		for (i = 0; i < n; i ++) if (sa[i] >= j) y[p ++] = sa[i] - j;
		for (i = 0; i < n; i ++) Wv[i] = x[y[i]];
		for (i = 0; i < m; i ++) Ws[i] = 0;
		for (i = 0; i < n; i ++) Ws[Wv[i]] ++;
		for (i = 1; i < m; i ++) Ws[i] += Ws[i - 1];
		for (i = n - 1; i >= 0; i --) sa[-- Ws[Wv[i]]] = y[i];
		for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i ++) {
			x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p ++;
		}
	}
	for (int i = 0; i < n; i ++) Rank[sa[i]] = i;
	calheight(r, sa, n - 1);
}

int gao1(int n) {
	memset(sa, 0, sizeof(sa));
	for (int i = 0; i < n; i ++) {
		r[i + n] = r[i] = str[i] - 'a' + 1;
	}
	n *= 2;
	r[n] = 0;
	da(r, sa, n + 1, 200);
	int maxindex;
	for (int i = n; i >= 1; i --) {
		if (sa[i] < N) {
			maxindex = i; break;
		}
	}
	int smallindex = sa[maxindex], h = height[maxindex];
	for (int i = maxindex - 1; i >= 1; i --) {
		h = min(height[i + 1], h);
		if (sa[i] < N) {
			if (h >= N) {
				smallindex = min(smallindex, sa[i]);
			}
		}
	}
	return smallindex;
}

int gao2(int n) {
	memset(sa, 0, sizeof(sa));
	for (int i = 0; i < n; i ++) {
		r[i + n] = r[i] = str1[i] - 'a' + 1;
	}
	n *= 2;
	r[n] = 0;
	da(r, sa, n + 1, 200);
	int maxindex;
	for (int i = n; i >= 1; i --) {
		if (sa[i] < N) {
			maxindex = i; break;
		}
	}
	int smallindex = sa[maxindex], h = height[maxindex];
	for (int i = maxindex - 1; i >= 1; i --) {
		h = min(height[i + 1], h);
		if (sa[i] < N) {
			if (h >= N) {
				smallindex = max(smallindex, sa[i]);
			}
		}
	}
	return smallindex;
}

void work() {
	memset(str, 0, sizeof(str));
	scanf("%d", &N);
	scanf("%s", str);
	for (int i = N; i < 2 * N; i ++) {
		str[i] = str[i - N];
	}
	int clockwise = gao1(N);
	for (int i = 0, j = N - 1; i < N; i ++, j --) {
		str1[i] = str1[i + N] = str[j];
	}
	int rclockwise = gao2(N);
	rclockwise = N - 1 - rclockwise;
	bool big = false, small = false;
	for (int i = 0; i < N; i ++) {
		int a = clockwise + i;
		if (a > N) a -= N;
		int b = rclockwise - i;
		if (b < 0) b += N;
		if (str[a] < str[b]) {
			big = true;
			break;
		} else if (str[a] > str[b]) {
			small = true;
			break;
		}
	}
	if (big) {
		printf("%d %d\n", rclockwise + 1, 1); return ;
	} else {
		printf("%d %d\n", clockwise + 1, 0); return ;
	}

	if (!small && !big) {
		if (rclockwise < clockwise) {
			printf("%d %d\n", rclockwise + 1, 1);
		} else {
			printf("%d %d\n", clockwise + 1, 0);
		}
		return ;
	}
	if (small) {
		printf("%d %d\n", clockwise + 1, 0); return ;
	}
	if (big) {
		printf("%d %d\n", rclockwise + 1, 1); return ;
	}
}
int main() {
#ifdef __SKT__
	freopen("in", "r", stdin);
#endif
	scanf("%d", &T);
	while (T --) {
		work();
	}
	return 0;
}
